<template>
    <el-dialog title="选择单项" v-loading="selectLoading" v-model="editFormVisible" :close-on-click-modal="false" top="5%">
        <sy-baselist
                :hideAdd="true"
                :hideEdit="true"
                :hideDel="true"
                :showSelect="true"
                @onSelect="onSelect"
                listUrl="server/business/Single.ashx?cmd=GetList"
                :fixWhere="fixWhere"
        >
            <el-table-column prop="FName" label="名字" width="150" sortable>
            </el-table-column>
            <el-table-column prop="FNote" label="备注" width="200" sortable>
            </el-table-column>
        </sy-baselist>
    </el-dialog>
</template>

<script>
    import util from '../../common/util'
    export default {
        data(){
            return {
                selectLoading:false,
                FSubitemID:0,
                editFormVisible:false
            }
        },
        computed:{
            fixWhere(){
                return "FID NOT IN (SELECT FSingleID from c_subitem_single where FSubitemID="+ this.FSubitemID+")"
            }
        },
        methods:{
            switchLoading(flag){
                this.selectLoading = flag;
            },
            _openAdd(row) {
                this.editFormVisible = true
                this.FSubitemID = row.FSubitemID
            },
            onSelect(row){
                let form={
                    FSubitemID:this.FSubitemID,
                    FSingleID:row.FID
                }
                util.post("server/business/SubitemSingle.ashx?cmd=Save",form,this.switchLoading,result=> {
                    this.editFormVisible = false
                    this.$emit("onSaveSuc",row)
                })
            }
        }
    }
</script>